const car=require('../models/carModel');
const wear=require('../models/wearModel');
var carModel=car.model;
var wearModel=wear.model;
//查询一个类型的衣服

async function findByWear(imgsrc) {
    var data=await wearModel.find({image:imgsrc});
    return data;
}
async function findByAll() {
    var data=await carModel.find({});
    return data;
}
async function findByCar(imgsrc) {
    var data=await carModel.find({image:imgsrc});
    return data;
}
async function addThing(thing) {
    // console.log('dao',thing);
    var data={};
    data.kind=thing.kind;
    data.title=thing.title;
    data.price=thing.price;
    data.image=thing.image;
    data.mem=thing.mem;
    // console.log('data',data);
    var data1=await carModel.create(data);
    return data;
}
async function deleteThing(imgsrc) {
    console.log('dao',imgsrc);
    var data=await carModel.remove({image:imgsrc});
    if(data.deletedCount>0){
        var data1=await carModel.find({});
        return data1;
    }
}
async function modifyThing(imgsrc,number) {
    var data=await carModel.update({image:imgsrc},{$inc:{number:1}});
    return data;
}
exports.findByAll=findByAll;
exports.findByCar=findByCar;
exports.findByWear=findByWear;
exports.addThing=addThing;
exports.deleteThing=deleteThing;
exports.modifyThing=modifyThing;

